package drive.Service.ServiceFormat;

import com.google.gson.Gson;
import drive.Mapper.UseraddrMapper;
import drive.Model.Useraddr;
import drive.Service.ServiceInterface.UseraddrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UseraddrServiceA implements UseraddrService {
    @Autowired
    private UseraddrMapper useraddrMapper;

    Gson gson = new Gson();

    @Override
    public String add(Useraddr userAddr) {
        int result = useraddrMapper.addUserAddr(userAddr);
        return "新增地址成功";
    }

    @Override
    public String findByUserID(int userID) {
        List<Useraddr> userAddrs = useraddrMapper.getUserAddr(userID);
        return gson.toJson(userAddrs);
    }

    @Override
    public String update(Useraddr userAddr) {
        int result = useraddrMapper.updateUserAddr(userAddr);
        return "更新地址成功";
    }

    @Override
    public String delete(int addrID) {
        int result = useraddrMapper.deleteUserAddr(addrID);
        return "删除地址成功";
    }
}
